<?php
include('../include/setup.php');
include('menu.php');

$content = "
<form action=\"\" method=\"post\">
Firstname
<br/>
<input type=\"text\" name=\"firstname\">
<br/>
Lastname<br/>
<input type=\"text\" name=\"lastname\"><br/>
Age<br/>
<input type=\"text\" name=\"age\"><br/>
<input type=\"submit\" name=\"submit\" value=\"Simpan\">
";

if(isset($_POST['submit'])){
	if(!empty($_POST['firstname']) && !empty($_POST['lastname']) && !empty($_POST['age'])){
		$query = "insert into customer (firstname,lastname,age) values('".addslashes($_POST['firstname'])."','".addslashes($_POST['lastname'])."','".addslashes($_POST['age'])."')";
		$rs = $db->Execute($query);
		if($rs === false){
			$content .="<strong>Insert gagal</strong><br/>";
			$smarty->assign("content",$content);
		} else {
			$content ="<strong>Insert berhasil</strong> <a href=\"listarray.php\">List Data</a>";
			$smarty->assign("content",$content);
		}
	} else {
		$content = "inputan harus diisi";
		$smarty->assign("content",$content);
	}
} else {
	$smarty->assign("content",$content);
}
$smarty->assign("title","Add");

//View
$smarty->display('index.tpl');
?>